﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ResistorMoudel;
namespace WeighMoudle
{
    public partial class Form1 : Form
    {

        //WeigherMoudel.HvcWeigher hvcWeigher1 = new WeigherMoudel.HvcWeigher("hvcWeigher1", true);
        //WeigherMoudel.HvcWeigher hvcWeigher2 = new WeigherMoudel.HvcWeigher("hvcWeigher2", true);
        //WeigherMoudel.HvcWeigher hvcWeigher3 = new WeigherMoudel.HvcWeigher("hvcWeigher3", true);
        //WeigherMoudel.HvcWeigher hvcWeigher4 = new WeigherMoudel.HvcWeigher("hvcWeigher4", true);

        //WeigherMoudel.HvcWeigher hvcWeigher5 = new WeigherMoudel.HvcWeigher("hvcWeigher5", true);
        //WeigherMoudel.HvcWeigher hvcWeigher6 = new WeigherMoudel.HvcWeigher("hvcWeigher6", true);
        //WeigherMoudel.HvcWeigher hvcWeigher7 = new WeigherMoudel.HvcWeigher("hvcWeigher7", true);
        //WeigherMoudel.HvcWeigher hvcWeigher8 = new WeigherMoudel.HvcWeigher("hvcWeigher8", true);

        HIOK2Resistor hipotCommunication1 = new HIOK2Resistor("HIPOT1", true);
        //HipotCommunication hipotCommunication2 = new HipotCommunication("HIPOT2", "测试2");
        //HipotCommunication hipotCommunication3 = new HipotCommunication("HIPOT3", "测试3");
        //HipotCommunication hipotCommunication4 = new HipotCommunication("HIPOT4", "测试4");
        public Form1()
        {
            InitializeComponent();
            //hvcWeigher1.AllowCommunicationSet = true;
            //hvcWeigher1.ConnectionChanged += HvcWeigher1_ConnectionChanged;

        }

        private void HvcWeigher1_ConnectionChanged(WeigherMoudel.Weigher arg1, bool arg2)
        {
            //if (arg2)
            //{
            //    File.AppendAllText("D:\\TESTCC.txt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "   重连OK\r\n");
            //}
            //else
            //{
            //    File.AppendAllText("D:\\TESTCC.txt", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff") + "   掉线。。。\r\n");
            //}
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //hvcWeigher1.FormShow(flowLayoutPanel1);
        }


        private void RecivceMsg()
        {
            IPEndPoint local = new IPEndPoint(IPAddress.Parse("192.168.0.65"), 10008);
            UdpClient udpClient = new UdpClient(local);
            //Socket socket=new Socket()
            IPEndPoint remote = new IPEndPoint(IPAddress.Parse("192.168.0.80"), 10123);
            string data = "hello";
            byte[] bts = Encoding.ASCII.GetBytes(data);
            udpClient.Send(bts, bts.Length, remote);
            while (true)
            {
                try
                {

                    byte[] recivcedata = udpClient.Receive(ref remote);
                    string strMsg = Encoding.ASCII.GetString(recivcedata, 0, recivcedata.Length);
                    //Console.WriteLine("UDP收到：" + strMsg);
                    //AddItem(listBoxRecv, string.Format("来自{0}：{1}", remote, strMsg));
                }
                catch(Exception exp)
                {
                    break;
                }
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            //hvcWeigher1.Zero(5000);
            string ss = "\r\n";
            byte[] bytes = ASCIIEncoding.ASCII.GetBytes(ss);

        }

        private void button3_Click(object sender, EventArgs e)
        {
            hipotCommunication1.FormShow(true);
        }

        private void button4_Click(object sender, EventArgs e)
        {
            //hvcWeigher3.FormShow(flowLayoutPanel1);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            //hvcWeigher4.FormShow(flowLayoutPanel1);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            //hvcWeigher5.FormShow(flowLayoutPanel1);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            //hvcWeigher6.FormShow(flowLayoutPanel1);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            //hvcWeigher7.FormShow(flowLayoutPanel1);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            //hvcWeigher8.FormShow(flowLayoutPanel1);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            button1_Click(null, null);
            //button3_Click(null, null);
            //button4_Click(null, null);
            //button5_Click(null, null);
            //button6_Click(null, null);
            //button7_Click(null, null);
            //button8_Click(null, null);
            //button9_Click(null, null);

        }

        private void button10_Click(object sender, EventArgs e)
        {
            //hipotCommunication1.FormShow();
        }

        private void button11_Click(object sender, EventArgs e)
        {
            //hipotCommunication2.FormShow();
        }

        private void button12_Click(object sender, EventArgs e)
        {
            //hipotCommunication3.FormShow();
        }

        private void button13_Click(object sender, EventArgs e)
        {
            //hipotCommunication4.FormShow();
        }
    }
}
